// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

namespace STSFederationMetadataEditor
{
    using System.Configuration;

    public class ClaimsCollection : ConfigurationElementCollection
    {
        public ClaimsCollection()
        {
            // TODO maybe to axe
            ////var claim = (ClaimConfigElement)this.CreateNewElement();
            ////this.Add(claim);
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        public new string AddElementName
        {
            get
            {
                return base.AddElementName;
            }

            set
            {
                base.AddElementName = value;
            }
        }

        public new string ClearElementName
        {
            get
            {
                return base.ClearElementName;
            }

            set
            {
                base.AddElementName = value;
            }
        }

        public new string RemoveElementName
        {
            get
            {
                return base.RemoveElementName;
            }
        }

        public new int Count
        {
            get { return base.Count; }
        }

        public ClaimConfigElement this[int index]
        {
            get
            {
                return (ClaimConfigElement)this.BaseGet(index);
            }

            set
            {
                if (this.BaseGet(index) != null)
                {
                    this.BaseRemoveAt(index);
                }

                this.BaseAdd(index, value);
            }
        }

        public new ClaimConfigElement this[string name]
        {
            get
            {
                return (ClaimConfigElement)this.BaseGet(name);
            }
        }

        public int IndexOf(ClaimConfigElement url)
        {
            return this.BaseIndexOf(url);
        }

        public void Add(ClaimConfigElement url)
        {
            this.BaseAdd(url);

            // Add custom code here.
        }

        public void Remove(ClaimConfigElement url)
        {
            if (this.BaseIndexOf(url) >= 0)
            {
                this.BaseRemove(url.Type);
            }
        }

        public void RemoveAt(int index)
        {
            this.BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            this.BaseRemove(name);
        }

        public void Clear()
        {
            this.BaseClear();

            // Add custom code here.
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ClaimConfigElement();
        }

        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            return new ClaimConfigElement(elementName);
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            this.BaseAdd(element, false);

            // Add custom code here.
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ClaimConfigElement)element).Type;
        }
    }
}